package com.demo.service.impl;

import com.demo.bo.CityBO;
import com.demo.dao.CityMapper;
import com.demo.dao.CommonMapper;
import com.demo.model.City;
import com.demo.service.ITestService;
import org.apache.commons.collections4.map.HashedMap;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/12/1.
 */
@Service
public class TestServiceImpl implements ITestService {
    @Autowired
    private CityMapper cityMapper;
    @Autowired
    private CommonMapper commonMapper;

    @Override
    public List<CityBO> selectCityList() {
        List<City> list = cityMapper.selectAll();
        List<CityBO> cityBOList = new ArrayList<>();
        for (City city : list) {
            CityBO cityBO = new CityBO();
            BeanUtils.copyProperties(city, cityBO);
            cityBOList.add(cityBO);
        }
        return cityBOList;
    }

    @Override
    public String createTableByOrginalTable(String name) {
        Map<String, Object> param = new HashedMap();
        param.put("tableName", name);
        param.put("orginalTableName", "city");
        int i = commonMapper.createTableByOrginalTable(param);
        return i+"";
    }
}
